#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

const int N = 10010;

struct Family
{
    int id, num;
    double cnt, s;
    double ans1, ans2;
    bool operator<(const Family &f)
    {
        if (ans2 != f.ans2)
        {
            return ans2 > f.ans2;
        }
        return id < f.id;
    }
} family[N];

vector<Family> ans;
bool legal[N];
int f[N];

int find(int i)
{
    if (f[i] == i)
    {
        return i;
    }
    return f[i] = find(f[i]);
}

void merge(int a, int b)
{
    legal[a] = legal[b] = true;
    int fa = find(a);
    int fb = find(b);
    if (fa != fb)
    {
        f[max(fa, fb)] = min(fa, fb);
    }
}

void init()
{
    for (int i = 0; i < N; i++)
    {
        f[i] = i;
        family[i].id = i;
    }
}

int main()
{
    int n;
    cin >> n;
    init();
    while (n--)
    {
        int id, fid, mid;
        cin >> id >> fid >> mid;
        legal[id] = true;
        if (fid != -1)
        {
            merge(id, fid);
        }
        if (mid != -1)
        {
            merge(id, mid);
        }
        int cnt;
        cin >> cnt;
        for (int i = 0; i < cnt; i++)
        {
            int sid;
            cin >> sid;
            merge(id, sid);
        }
        cin >> family[id].cnt >> family[id].s;
    }
    for (int i = 0; i < N; i++)
    {
        if (legal[i] && find(i) == i)
        {
            family[i].num = 1;
            for (int j = 0; j < N; j++)
            {
                if (i != j && find(j) == i)
                {
                    family[i].num++;
                    family[i].cnt += family[j].cnt;
                    family[i].s += family[j].s;
                }
            }
            family[i].ans1 = family[i].cnt / family[i].num;
            family[i].ans2 = family[i].s / family[i].num;
            ans.push_back(family[i]);
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for (auto it = ans.begin(); it != ans.end(); it++)
    {
        printf("%04d %d %.3f %.3f\n", it->id, it->num, it->ans1, it->ans2);
    }
    return 0;
}